const express = require('express')
const fs = require('fs')
const router = require('./router/index')
const https = require('https')
const cors = require('cors')
const bodyParser = require('body-parser')
// 创建 express 应用
const app = express()
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())


app.use(cors())
app.use(router)



const privateKey = fs.readFileSync('./ca/5615458_book.yueying.cool.key', 'utf8')
const certificate = fs.readFileSync('./ca/5615458_book.yueying.cool.pem', 'utf8')
const credentials = { key: privateKey, cert: certificate }
const httpsServer = https.createServer(credentials, app)
const SSLPORT = 18082
httpsServer.listen(SSLPORT, function() {
  console.log('HTTPS Server is running on: https://book.yueying.cool:%s', SSLPORT)
})